package cn.javabb.controller;

import cn.javabb.common.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.net.URL;
import java.util.List;
import java.util.Map;

/**
 * @desc:
 * @author: javabb (javabob(a)163.com)
 * @create: 2020/05/28 22:06
 */
@RestController
@RequestMapping("/student")
public class StudentConsumerController {
    @Autowired
    private RestTemplate restTemplate;

    //public static final String URL_PRE = "http://localhost:1001";
    public static final String URL_PRE = "http://STUDENT-PROVIDER-SERVER"; //用服务提供者的应用名称,最好是大写

    @GetMapping("/all")
    public Object queryAll() {
        return restTemplate.getForObject(URL_PRE + "/student/all", List.class);
    }

    @PostMapping("/save")
    public Object save(Student student) {
        return restTemplate.postForEntity(URL_PRE + "/student/save", student, Boolean.class);
    }

    @GetMapping("/query/{id}")
    public Object queryone(@PathVariable("id") Integer id) {
        return restTemplate.getForObject(URL_PRE + "/student/query/" + id, Student.class);
    }

    @GetMapping("/delete/{id}")
    public Object delete(@PathVariable("id") Integer id) {
        return restTemplate.getForObject(URL_PRE + "/student/delete/" + id, Boolean.class);
    }

    @GetMapping("/getInfo")
    public Object getInfo() {
        return restTemplate.getForObject(URL_PRE + "/student/getInfo/", Map.class);
    }

}
